<input type="hidden" name='url' id='url' value="<?php echo $this->Html->url( null, true ); ?>">
<div class="row">
 	<div class="col-md-12">
		<div class="page-header">
		  <h1>Usuarios</h1>
		</div>

		<div class="row">
			<div class="col-md-6">		
				<div class="btn-group pull-left">			
					<?php echo $this->Html->link(__('Nuevo', true), array('controller' => 'users', 'action' => 'add' ),array('class'=>'btn btn-default btn-ls')); ?> 	
					<a href="#" class="btn btn-default btn-ls" id='edit_bt'>Editar</a>		
					<a href="#" class="btn btn-default btn-ls" id='delete_bt'>Eliminar</a>		
				</div>
			</div>
		</div>

		<br>
		<br>
			
		
		<table class="table table-hover table-striped table-bordered">
			<thead>
				<tr>
					<th>#</th>
					<th><?php echo $this->Paginator->sort('username', 'Usuario'); ?></th>
					<th><?php echo $this->Paginator->sort('first_name', 'Nombre'); ?></th>
					<th><?php echo $this->Paginator->sort('last_name', 'Apellido'); ?></th>
					<th><?php echo $this->Paginator->sort('group_id', 'Tipo Usuario'); ?></th>
					<th><?php echo $this->Paginator->sort('created', 'Creado'); ?></th>
				</tr>
			</thead>
			<tbody>
				<?php foreach ($data as $item) :?>
					<tr>
						<td><input type="checkbox" name='users_id[]' value="<?php echo $item['User']['id']?>"></td>
						<td><?php echo $item['User']['username']?></td>
						<td><?php echo $item['User']['last_name']?></td>
						<td><?php echo $item['User']['first_name']?></td>
						<td><?php echo $item['Group']['name']?></td>
						<td><?php echo date( 'd-m-Y H:i:s', strtotime($item['User']['created'])); ?></td>						
					</tr>
				<?php endforeach;?>	
			</tbody>
		</table>
			  <ul class="pagination">
			        <?php 
			            echo $this->Paginator->prev( '<<', array( 'class' => '', 'tag' => 'li' ), null, array( 'class' => 'disabled', 'tag' => 'li' ) );
			            echo $this->Paginator->numbers( array( 'tag' => 'li', 'separator' => '', 'currentClass' => 'active', 'currentTag' => 'a' ) );
			            echo $this->Paginator->next( '>>', array( 'class' => '', 'tag' => 'li' ), null, array( 'class' => 'disabled', 'tag' => 'li' ) );
			        ?>
			    </ul>


	</div> 
</div>

<script type="text/javascript">
	function get_check_id(){
	    var result=0;
	    //users_ids
	    $('input[name=users_id\\[\\]]').each(function() {
	        if( $(this).is(":checked")){
	            var user_id = $(this).val();	           
	            result =  user_id;
	        }
	    });
	    return result;
	}
$(function(){
	var url=$("#url").val();
	//console.debug("URL: %o",url);
	$("#edit_bt").click(function(){
		chck_id= get_check_id();
		redirect_url=url+"/edit/"+chck_id
		//console.debug("redirect_url: %o",redirect_url);
		window.location.replace(redirect_url);
		return false;
	});
	$("#delete_bt").click(function(){
		chck_id= get_check_id();
		redirect_url=url+"/delete/"+chck_id
		//console.debug("redirect_url: %o",redirect_url);
		window.location.replace(redirect_url);
		return false;
	});
});
</script>
